package p0;

public class Leetcode_98 {
    /**
     * Definition for a binary tree node.
     */
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }


    public boolean isValidBST(TreeNode root) {
        return validate(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    private boolean validate(TreeNode root, long minValue, long maxValue) {
        return root == null || (root.val > minValue && root.val < maxValue && (validate(root.left, minValue, root.val) && validate(root.right, root.val, maxValue)));
    }

    public static void main(String[] args) {
        System.out.println();
    }
}
